<template>
	<view class="y-y-box">
		<view class="y-tab">
			<text :class="{active:body.status==1}" @click="changeTab(1)">预约中</text>
			<text :class="{active:body.status==2}" @click="changeTab(2)">匹配成功</text>
		</view>
		<view class="y-list">
			<view class="y-l-item"  v-for="item in list" :key="item.id">
				<view class="top">
					<text class="name">预约 {{item.price}} 拼团</text>
					<text class="status" v-if="item.status==1" key="1">预约中</text>
					<text class="status status2" v-if="item.status==2" key="2">匹配成功</text>
				</view>
				<view class="time">
					<text>预约时间：</text>
					<text>{{item.created_at}}</text>
				</view>
			</view>
			<view class="empty_loading2">
				<image v-if="body.shoLoading" src="@/pages/groupbuy/static/loading.gif"></image>
				<view v-if="body.showEmpty">———— <text>没有更多了</text> ————</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		debounce
	} from 'lodash'
	export default {
		data() {
			return {
				body: {
					status: 1, //1预约中 ,2匹配成功
					shoLoading: false, //加载中
					showEmpty: false, //没有更过了
				},
				list: [],
			}
		},
		mounted() {
			this.inti()
		},
		methods: {
			inti() {
				this.body = {
					status: 1, //1预约中 ,2匹配成功
					shoLoading: false, //加载中
					showEmpty: false, //没有更过了
				}
				this.list = []
				this.getList()
			},
			changeTab: debounce(function(e) {
				this.body.status = e
				this.list = []
				this.getList()
			}, 200),
			async getList() {
				this.body.shoLoading = true;
				this.body.showEmpty = false;
				const status = this.body.status
				const res = await this.$axios('ReservationLog/details', 'POST', 'pintuan', this.body)
				this.body.shoLoading = false;
				if (status != this.body.status) {
					return
				}
				if (res.data.code == 200) {
					this.list = res.data.data.list || []
					this.body.showEmpty = this.list.length <= 0;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.y-y-box {
		padding: 0 20rpx;

		.y-tab {
			display: flex;
			align-items: center;

			text {
				font-weight: bold;
				font-size: 28rpx;
				line-height: 60rpx;
				text-align: center;
				border-radius: 10rpx;
				flex: 1;
			}

			.active {
				color: #9A1FE8;
			}
		}

		.y-list {
			padding: 0 0 20rpx;

			.y-l-item {
				background-color: #fff;
				border-radius: 10rpx;
				padding: 20rpx;
				margin-top: 20rpx;

				.top {
					padding: 10rpx 0;
					font-weight: bold;
					display: flex;

					.name {
						font-size: 28rpx;
						font-weight: bold;
						flex: 1;
					}

					.status {
						background: rgba(#9A1FE8, 0.1);
						color: #9A1FE8;
						padding: 0 15rpx;
						line-height: 45rpx;
						height: 45rpx;
						font-size: 24rpx;
						border-radius: 6rpx;
					}

					.status2 {
						background: #9A1FE8;
						color: #fff;
					}
				}

				.time {
					padding: 10rpx 0;
					font-size: 24rpx;
					color: rgba(#9A1FE8, 1);
				}
			}
		}
	}
</style>